﻿namespace Arms.Framework.Collections
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// Add only collection.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class AddOnlyCollection<T> : IAddOnlyCollection<T>
    {
        private List<T> _items;
        public AddOnlyCollection() : this(new List<T>()) { }
        public AddOnlyCollection(List<T> values)
        {
            _items = values;
        }
        /// <summary>
        /// Gets the item at index.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public T this[int index]
        {
            get { return _items[index]; }
        }
        /// <summary>
        /// Number of items in this collection.
        /// </summary>
        public int Count { get { return _items.Count; } }
        /// <summary>
        /// Adds an item to this collection.
        /// </summary>
        /// <param name="item">item to add</param>
        public void Add(T item)
        {
            _items.Add(item);
        }
        /// <summary>
        /// Adds a distinct item to this collection.
        /// </summary>
        /// <param name="item">item to add</param>
        public void AddDistinct(T item)
        {
            _items.AddDistinct(item);
        }

        public IEnumerator<T> GetEnumerator()
        {
            return _items.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
}
